package com.dao.impl;

import com.dao.BaseDao;

import com.dao.intf.CommentDao;
import com.entity.Comment;

import java.util.List;

public class CommentDaoImpl extends BaseDao implements CommentDao {
    @Override
    public List<Comment> queryCommentByBlogId(Integer blogId) {
        String sql="SELECT * FROM `comment` WHERE `blogId`=?";

        return queryForList(Comment.class,sql,blogId);
    }

    @Override
    public int addComment(Comment comment) {

        String sql=" INSERT INTO `comment` (`userId`,`authorId`,`blogId`,`comment`,`userName`) VALUES(?,?,?,?,?)";
        return update(sql,comment.getUserId(),comment.getAuthorId(),comment.getBlogId(),comment.getComment(),comment.getUserName());
    }

    @Override
    public int deleteComment(Integer commentId) {
        String sql="DELETE FROM `comment` WHERE `id` =? ";

        return update(sql,commentId);
    }
}
